<template>
  <div>

    <div style="height:60px;padding: 0 1.2rem;" class="row container">

      <router-link :to="{ path: '/', query: {}}" class="col-2 text-left">
        <img src="../../static/img/logo.png" alt="logo" style="width:70px;">
      </router-link>
      <div class="col-4">
      </div>
      <div href="#" class="col-6 text-right"  style="padding-top:20px;">
        <button type="button" class="btn btn-light btn-sm">登录</button>
        <button type="button" class="btn btn-light btn-sm">注册</button>
      </div>
    </div>

    <ul class="nav nav-pills container" style="padding:1rem 2rem;">
      <li class="nav-item">
        <router-link class="nav-link" :to="{ path: '/', query: {}}">常用网站</router-link>
      </li>

      <li class="nav-item">
        <router-link class="nav-link active" :to="{ path: '/stockindex', query: {}}">大盘指数</router-link>
      </li>

      <li class="nav-item">
        <router-link class="nav-link" :to="{ path: '/news', query: {}}">财经头条</router-link>
      </li>
      
      <li class="nav-item">
        <router-link class="nav-link" :to="{ path: '/discuss', query: {}}">个股说说</router-link>
      </li>

      <li class="nav-item">
        <router-link class="nav-link" :to="{ path: '/plan', query: {}}">灵气策略</router-link>
      </li>
    </ul>

    <div style="height:20px;background-color:#e9ecef73;margin-bottom:20px;"></div>

    <ul class="nav nav-tabs nav-justified container">
      <li class="nav-item">
        <router-link  class="nav-link active" :to="{ path: '/stockindex', query: {}}">实时指数</router-link>
      </li>
      <li class="nav-item">
        <router-link  class="nav-link" :to="{ path: '/moreindex', query: {}}">更多指数</router-link>
      </li>
      <li class="nav-item">
        <router-link  class="nav-link" :to="{}">待定</router-link>
      </li>
    </ul>

    <div class="container-fluid container" style="padding:2rem;">
      <div class="row">

        <div class="col-6 col-sm-6 col-md-4 col-lg-4 col-xl-4" v-for = "(item, index) in nowIndex" :index="index" :key="item.index">
          <div class="card">
            <div class="card-body">
              <h5 class="card-title"> {{item.name}} </h5>
              <h5 class="card-text"> {{(item.price - 0).toPrecision(4)}} </h5>
              <p class="card-text text-danger" v-if="item.price - item.pre_close >= 0"> {{(item.price - item.pre_close).toPrecision(4)}} </p>
              <p class="card-text text-success" v-else> {{(item.price - item.pre_close).toPrecision(4)}} </p>
              <p class="card-text text-danger" v-if="item.price - item.pre_close >= 0"> {{((item.price - item.pre_close) / item.pre_close * 100).toPrecision(4)}}% </p>
              <p class="card-text text-success" v-else> {{((item.price - item.pre_close) / item.pre_close * 100).toPrecision(4)}}% </p>
            </div>
          </div>
        </div>
     
      </div>
    </div>

    <!-- foot -->
    <Footer/>

  </div>
</template>

<script>
import Footer from '../components/Footer.vue'

export default {
  components: {
    Footer
  },
  data () {
    return {
      nowIndex:[]
    }
  },
  created() {
    this.axios.get(`${this.config.baseURL}:${this.config.port}/api/stock_index?id=now_index`).then((response) => {
      // console.log('sdsdf', response.data.data)
      this.nowIndex = response.data.data
    })
  },
  methods: {
    go () {
      this.$router.push('/moreindex')
    },
  // 注册
  getSite() {
    this.$axios.get('/website/siteList').then(({status,data})=>{
        if(status===200){
          if(data&&data.code === 1){
            console.log('this.middleList', data.data.favorite)
            this.middleList = data.data.favorite

            // setTimeout(()=>{
            //   this.$message.success('取出成功');
            // }, 2300)
          } else if(data&&data.code === 0) {
            this.middleList = data.data
          } else {
            // this.error=data.msg
            // this.$message.error(data.msg);
          }
        }else{
          this.error=`服务器出错`
        }
      })
    }
  }  
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  /* color: #42b983; */
}
.card {
   margin-bottom:2rem
}
.nav-link.active {
  background-color: #409eff;
  color:#fff;
}
</style>
